
import time, datetime
from pymongo import MongoClient
from bson import ObjectId
import pymysql
import traceback

dbs = {
    "mongo-local": {
        "host": "127.0.0.1",
        "port": 27017,
        "username": "brotherbaby",
        "password": "q1w2e3r4",
        "authSource": "mytest"
    },
    "tidb-ycs1y": {
        "host": "10.246.240.103",
        "port": 4000,
        "user": "ods_s1y_his_select",
        "password": "wxIoSJOkghDtRUGb",
        "db": "ods_s1y_his"
    }
}

mongodb_ins = MongoClient(**dbs["mongo-local"]).mytest


def do_biz():
    pps = mongodb_ins.XHHK_ProblemPatInfo.find({"id_number_mismatch": 1})

    # compare....
    for pp in pps:
        if not (pp.get("xhhk_id_number") and pp.get("his_id_number")):
            continue
        if str(pp.get("xhhk_id_number")).upper() == str(pp.get("his_id_number")).upper():
            up_id_number_mismatch = 0
            if pp.get("his_nonexists") == 0 and pp.get("name_mismatch") == 0 and pp.get("gender_mismatch") == 0 \
                    and pp.get("telephone_mismatch") == 0 and pp.get("address_mismatch") == 0:
                mongodb_ins.XHHK_ProblemPatInfo.delete_one({"_id": pp.get("_id")})
            else:
                mongodb_ins.XHHK_ProblemPatInfo.update_one({"_id": pp.get("_id")}, {"$set": {"id_number_mismatch": 0}})


def main():
    do_biz()

if __name__ == '__main__':
    main()
